package com.koron.css2.newProjectCenter.impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.koron.css2.ServerInterface;
import com.koron.css2.newProjectCenter.bean.PjMeter;
import com.koron.css2.newProjectCenter.bean.query.PjMeterQuery;
import com.koron.css2.newProjectCenter.mapper.PjMeterMapper;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.List;

/**
 * 水表明细分页查询 与  PjMeterList 一致
 */
public class PjMeterPageList implements ServerInterface {
    @Override
    public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
        try {
            PjMeterQuery pjMeterQuery = JsonUtils.objectToPojo(req.getData(), PjMeterQuery.class);
            PjMeterMapper pjMeterMapper = factory.getMapper(PjMeterMapper.class);
            PageHelper.startPage(pjMeterQuery.getPage(), pjMeterQuery.getPageCount());
            List<PjMeter> pjMeterList = pjMeterMapper.getList(pjMeterQuery);
            PjMeterList.covertMeterInfo(factory, pjMeterList);
            // 9. 返回结果
            MessageBean<PageInfo> messageBean = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "立户列表分页查询成功", PageInfo.class);
            messageBean.setData(new PageInfo<>(pjMeterList));
            return messageBean;
        } catch (Exception e) {
            logger.error("立户列表分页查询失败", e);
            return MessageBean.create(Constant.MESSAGE_INT_FAIL, "立户列表分页查询失败:", null);
        }
    }
}
